Passed
Push — master ( 4c2534...c3984e )
by Christiaan
54s queued 10s
created

createConnect.js ➔ ???   A

Complexity

Conditions 1
Paths 0

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 0
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
import React from 'react'
2
import { compose } from 'ramda'
3
4
import fromRenderProps from './fromRenderProps'
5
import setHocDisplayName from './setHocDisplayName'
6
import { stateToProps } from './stateToProps'
7
8
/**
9
 * This function creates a HOC for connect the given global store context to the given Component.
10
 * Only the props provided through the
11
 * @param {React.Context} GlobalStoreContext The global store context
12
 * @function
13
 * @return connect HOC
14
 */
15
export const createConnect = GlobalStoreContext => mapStateToProps => Component =>
16
  compose(
17
    setHocDisplayName('connect', Component),
18
    fromRenderProps(GlobalStoreContext.Consumer, stateToProps(mapStateToProps)), // connect with consumer
19
    React.memo // Do not unnessasary rerender
20
  )(Component)
21